package io.renren.modules.sys.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.sys.entity.CourseuserEntity;
import io.renren.modules.sys.service.CourseuserService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 学生关联课程表
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2019-10-31 17:53:34
 */
@RestController
@RequestMapping("sys/courseuser")
public class CourseuserController {
    @Autowired
    private CourseuserService courseuserService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:courseuser:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = courseuserService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:courseuser:info")
    public R info(@PathVariable("id") Integer id){
        CourseuserEntity courseuser = courseuserService.getById(id);

        return R.ok().put("courseuser", courseuser);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:courseuser:save")
    public R save(@RequestBody CourseuserEntity courseuser){
        courseuserService.save(courseuser);

        return R.ok();
    }

    /**
     * 选中
     */
//    @RequestMapping("/pass")
//    public R pass(@RequestBody Integer[] ids) {
//        List list = Arrays.asList(ids);
//        String id= null;
//        CourseuserEntity courseuserEntity = new CourseuserEntity();
//        for (int i=0;i<list.size();i++){
//            id = list.get(i).toString();
//            courseuserEntity = courseuserService.getById(id);
//            courseuserEntity.setStatu(1);
//            courseuserService.updateById(courseuserEntity);
//        }
//        return R.ok();
//    }

    /**
     * 取消选中
     */
//    @RequestMapping("/nopass")
//    public R nopass(@RequestBody Integer[] ids) {
//        List list = Arrays.asList(ids);
//        String id= null;
//        CourseuserEntity courseuserEntity = new CourseuserEntity();
//        for (int i=0;i<list.size();i++){
//            id = list.get(i).toString();
//            courseuserEntity = courseuserService.getById(id);
//            courseuserEntity.setStatu(0);
//            courseuserService.updateById(courseuserEntity);
//        }
//        return R.ok();
//
//    }

    /**
     * 选中
     */
    @RequestMapping("/pass")
    public R pass(@RequestBody Integer id) {
        CourseuserEntity courseuserEntity = courseuserService.getById(id);
        courseuserEntity.setStatu(1);
        courseuserService.updateById(courseuserEntity);

        return R.ok();
    }

    /**
     * 取消选中
     */
    @RequestMapping("/nopass")
    public R nopass(@RequestBody Integer id) {
        CourseuserEntity courseuserEntity = courseuserService.getById(id);
        courseuserEntity.setStatu(3);
        courseuserService.updateById(courseuserEntity);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:courseuser:update")
    public R update(@RequestBody CourseuserEntity courseuser){
        ValidatorUtils.validateEntity(courseuser);
        courseuserService.updateById(courseuser);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:courseuser:delete")
    public R delete(@RequestBody Integer[] ids){
        courseuserService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    @RequestMapping("/deleteById")
    public R deleteById(@RequestBody Integer id){
        courseuserService.removeById(id);

        return R.ok();
    }

}
